Skip to content

MA0011: suppress diagnostic when all AppendFormat template arguments are culture-insensitive#1085

Merged
meziantou merged 2 commits into
mainfrom
copilot/fix-ma0011-case-insensitivity
Apr 2, 2026
Merged

MA0011: suppress diagnostic when all AppendFormat template arguments are culture-insensitive#1085
meziantou merged 2 commits into
mainfrom
copilot/fix-ma0011-case-insensitivity

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 2, 2026

MA0011 was incorrectly flagged on StringBuilder.AppendFormat calls where every template argument is culture-insensitive (strings, chars, booleans, positive integers, etc.), because CultureSensitiveFormattingContext.IsCultureSensitiveOperation had no special handling for AppendFormat and defaulted to true.

Changes

  • CultureSensitiveFormattingContext.cs: Added AppendFormat handling on StringBuilder mirroring the existing string.Format logic — skips the format-string argument, then checks each template argument; returns false if none are culture-sensitive. Handles the params object[], collection-expression (Roslyn 4.14+), and individual-argument overload shapes.

  • UseIFormatProviderAnalyzerTests.cs: Updated the existing AppendFormat("{0}", 10) test (positive int → not culture-sensitive, no longer warrants a diagnostic; changed to -1); added no-diagnostic cases for "{0} / {1}", "X", "Y" and "{0}", 10.

Example

var sb = new StringBuilder();
sb.AppendFormat("{0} / {1}", "X", "Y");   // no longer reported
sb.AppendFormat("{0}", 10);               // no longer reported (positive int)
sb.AppendFormat("{0}", -1);              // still reported (negative int is culture-sensitive)

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • st8vsblobprodcus339.vsblob.vsassets.io
    • Triggering command: /usr/share/dotnet/dotnet dotnet restore --no-dependencies /home/REDACTED/work/Meziantou.Analyzer/Meziantou.Analyzer/Meziantou.Analyzer.slnx --packages /tmp/codeql-scratch-8ad8dc5536a632e8/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-8ad8dc5536a632e8/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-8ad8dc5536a632e8/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)
    • Triggering command: /usr/share/dotnet/dotnet dotnet restore --no-dependencies /home/REDACTED/work/Meziantou.Analyzer/Meziantou.Analyzer/tests/Meziantou.Analyzer.Test/Meziantou.Analyzer.Test.csproj --packages /tmp/codeql-scratch-8ad8dc5536a632e8/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-8ad8dc5536a632e8/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-8ad8dc5536a632e8/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

…e culture-insensitive

Agent-Logs-Url: https://github.com/meziantou/Meziantou.Analyzer/sessions/cd874975-1da8-47b9-a17f-9bf3a890c81e

Co-authored-by: meziantou <509220+meziantou@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix MA0011 reporting for case-insensitive template arguments MA0011: suppress diagnostic when all AppendFormat template arguments are culture-insensitive Apr 2, 2026
Copilot AI requested a review from meziantou April 2, 2026 14:12
@meziantou meziantou marked this pull request as ready for review April 2, 2026 14:15
@meziantou meziantou merged commit 7e3fab3 into main Apr 2, 2026
13 checks passed
@meziantou meziantou deleted the copilot/fix-ma0011-case-insensitivity branch April 2, 2026 14:26
This was referenced Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MA0011 should not be reported when all "template arguments" are case-insensitive

2 participants